﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using TyMES.Model.BaseInformation;
using TyMES.Model;

namespace TyMES.ViewModel.BaseInformation.MachineVMs
{
    public partial class MachineListVM : BasePagedListVM<Machine_View, MachineSearcher>
    {
        
        protected override IEnumerable<IGridColumn<Machine_View>> InitGridHeader()
        {
            return new List<GridColumn<Machine_View>>{
                
                this.MakeGridHeader(x => x.Machine_LineCode).SetTitle(@Localizer["Page.设备产线"].Value),
                this.MakeGridHeader(x => x.Machine_StationCode).SetTitle(@Localizer["Page.设备所在工位"].Value),
                this.MakeGridHeader(x => x.Machine_MachineCode).SetTitle(@Localizer["Page.设备编码"].Value),
                this.MakeGridHeader(x => x.Machine_MachineName).SetTitle(@Localizer["Page.设备名称"].Value),
                this.MakeGridHeader(x => x.Machine_Asset).SetTitle(@Localizer["Page.资产号"].Value),
                this.MakeGridHeader(x => x.Machine_RatedPower).SetTitle(@Localizer["Page.额定功率"].Value),
                this.MakeGridHeader(x => x.Machine_AtmPressure).SetTitle(@Localizer["Page.气压"].Value),
                this.MakeGridHeader(x => x.Machine_Voltage).SetTitle(@Localizer["Page.电压"].Value),
                this.MakeGridHeader(x => x.Machine_Current).SetTitle(@Localizer["Page.电流"].Value),
                this.MakeGridHeader(x => x.Machine_PersonCode).SetTitle(@Localizer["Page.责任人"].Value),
                this.MakeGridHeader(x => x.Machine_MachineStatus).SetTitle(@Localizer["Page.设备状态"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<Machine_View> GetSearchQuery()
        {
            var query = DC.Set<Machine>()
                
                .CheckEqual(Searcher.LineCodeId, x=>x.LineCodeId)
                .CheckEqual(Searcher.StationCodeId, x=>x.StationCodeId)
                .CheckContain(Searcher.MachineCode, x=>x.MachineCode)
                .CheckContain(Searcher.MachineName, x=>x.MachineName)
                .CheckContain(Searcher.Asset, x=>x.Asset)
                .CheckEqual(Searcher.RatedPower, x=>x.RatedPower)
                .CheckContain(Searcher.PersonCode, x=>x.PersonCode)
                .CheckEqual(Searcher.MachineStatus, x=>x.MachineStatus)
                .Select(x => new Machine_View
                {
				    ID = x.ID,
                    
                    Machine_LineCode = DC.Set<Line>().Where(z0 => z0.LineCode == x.LineCodeId).Select(y => y.LineCode).FirstOrDefault(),
                    Machine_StationCode = DC.Set<Station>().Where(z0 => z0.StationCode == x.StationCodeId).Select(y => y.StationCode).FirstOrDefault(),
                    Machine_MachineCode = x.MachineCode,
                    Machine_MachineName = x.MachineName,
                    Machine_Asset = x.Asset,
                    Machine_RatedPower = x.RatedPower,
                    Machine_AtmPressure = x.AtmPressure,
                    Machine_Voltage = x.Voltage,
                    Machine_Current = x.Current,
                    Machine_PersonCode = x.PersonCode,
                    Machine_MachineStatus = x.MachineStatus,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class Machine_View: Machine
    {
        
        public string Machine_LineCode { get; set; }
        public string Machine_StationCode { get; set; }
        public string Machine_MachineCode { get; set; }
        public string Machine_MachineName { get; set; }
        public string Machine_Asset { get; set; }
        public float? Machine_RatedPower { get; set; }
        public float? Machine_AtmPressure { get; set; }
        public float? Machine_Voltage { get; set; }
        public float? Machine_Current { get; set; }
        public string Machine_PersonCode { get; set; }
        public EquipmentStatusEnum? Machine_MachineStatus { get; set; }

    }

}